import { Toast } from "@/utils/toast";
import Taro, { request } from "@tarojs/taro";

let baseUrl = "http://apitest.lrjy.yunchuangshengya.com";
export function _customRequest(options: request.Option) {
  return Taro.request({
    ...options,
    url: `${baseUrl}/${options.url}`,
  }).then(res => {
    let { data } = res;
    if (data.code === 200) {
      return data.result;
    } else {
      Toast(data.msg || data.code);
      console.error("请求错误:", data);
      throw data;
    }
  });
}
export const customRequest = {
  get(url, data?) {
    _customRequest({
      url,
      data,
      method: "GET",
    });
  },
  post(url, data?) {
    _customRequest({
      url,
      data,
      method: "POST",
    });
  },
};
